/**
 * @author 黄波
 * 创建日期：2011Oct 13, 2011
 * TODO// N/A
 */
package com.platform.os.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import org.apache.struts2.ServletActionContext;

/**
 * 发送邮件工具类
 */
public class Mail {

	public static Properties PRO_FILE = null;
	/**
	 * 發送email
	 * @param content 要发送的内容
	 * @param to 收件人地址
	 * 
	 */
	public static void sendMail(String title, String content, String to) {
		if(PRO_FILE == null) {
			return;
		}
		if(to == null || to.equals("")) {
			return;
		}
		Properties props = new Properties();
		props.setProperty("mail.smtp.auth", "true");
		props.setProperty("mail.transport.protocol", "smtp");
		Session session = Session.getInstance(props);
		session.setDebug(false);
		Message msg = new MimeMessage(session);
		try {
			// 发送的邮箱地址
			msg.setFrom(new InternetAddress(PRO_FILE.getProperty("system_email_addr")));
			msg.setSubject(title);
			msg.setContent(content,
					"text/html;charset=gbk;");
			Transport transport = session.getTransport();
			// 设置服务器以及账号和密码
			transport.connect(PRO_FILE.getProperty("system_smtp"), 25, PRO_FILE.getProperty("system_email_name"), PRO_FILE.getProperty("system_email_passwd"));
			// 发送到的邮箱地址
			transport.sendMessage(msg, new Address[] { new InternetAddress(
					to) });
			transport.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
//		Mail.sendMail("您的密碼被重置為：123456", "308102796@qq.com");
	}
}
